<template>
	<view class="navbar">
		<view class="navbar-fixed">
			<!-- 状态栏 -->
			<view :style="{height:statusBarHeight+'px'}"></view>
			<!-- 导航栏内容 -->
			<view class="navbar-content" :style="{height:navBarHeight+'px',
			width:windowWidth+'px'}">
				<view class="navbar-serach">
				<view class="navbar-serach_icon">
					<uni-icons type="search" size="16" color="#999"></uni-icons>
				</view>
				<view class="navbar-serach_text">uniapp、vue</view>
			</view>
			</view>
		</view>
		<view :style="{height:statusBarHeight+navBarHeight+'px'}"></view>
	</view>
</template>

<script>
	export default {
		name:"navbar",
		data() {
			return {
				stausBarHeight:20,
				navBarHeight:45,
				windowWidth:375
			};
		},
		created() {
		   // 获取手机系统信息
			const info = uni.getSystemInfoSync()
			
			// 设置状态栏
			this.statusBarHeight = info.statusBarHeight
			this.windowWidth = info.windowWidth
			
			// h5 app mp-alipay
			// #ifndef H5 || APP-PLUS ||MP-ALIPAY
			// 获取胶囊的位置
			const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			console.log(menuButtonInfo);
			// (胶囊底部高度-状态栏的高度)+(胶囊顶部高度-状态栏内的高度)
			// =导航栏的高度
			this.navBarHeight = (menuButtonInfo.bottom - info.statusBarHeight)+
			(menuButtonInfo.top - info.statusBarHeight)
			this.windowWidth = menuButtonInfo.left
			// #endif
		
			
		}
	}
</script>

<style lang="scss">
	@import '../../common/css/icons.css';
    .navbar {
		.navbar-fixed {
		position: fixed;
		top:0;
		left:0;
		z-index:99;
		width:100%;
		background-color:$mk-base-color;
		.navbar-content{
			height:45px;
			padding: 0 15px;
			box-sizing: border-box;
			display: flex;
			justify-content: center;
			align-items: center;
			.navbar-serach {
				display: flex;
				align-items: center;
				padding: 0 10px;
				width:100%;
				height:30px ;
				border-radius: 30px;
				background-color: #fff;
				.navbar-serach_icon {
					// width: 10px;
					// height: 10px;
					// border: 1px red solid;
					margin-right: 10px;
				}
				.navbar-serach_text {
					font-size:12px;
					color: #999;
				}
			}	
		}
		}
	}
</style>
